package com.fr.chart.plot;

import com.fr.base.FCloneable;
import com.fr.base.XMLable;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.DataSeriesCondition;
import com.fr.chart.base.equals.Equals;
import com.fr.report.io.xml.ReportXMLUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SeriesAttr
  implements XMLable
{
  private static final long serialVersionUID = 4935620034917254185L;
  public static final String XML_TAG = "SeriesAttr";
  private List conditionList = new ArrayList();
  private Map categoryAttrMap = new HashMap();

  public int conditionCount()
  {
    return this.conditionList.size();
  }

  public DataSeriesCondition getCondition(int paramInt)
  {
    return ((DataSeriesCondition)this.conditionList.get(paramInt));
  }

  public void addCondition(DataSeriesCondition paramDataSeriesCondition)
  {
    this.conditionList.add(paramDataSeriesCondition);
  }

  public DataSeriesCondition isContains(DataSeriesCondition paramDataSeriesCondition)
  {
    for (int i = 0; i < conditionCount(); ++i)
      if (Equals.equals(paramDataSeriesCondition.getClass().getName(), getCondition(i).getClass().getName()))
        return getCondition(i);
    return null;
  }

  public void removeAll()
  {
    this.conditionList.clear();
  }

  public String getSeriesAttrType()
  {
    return "SeriesAttr";
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("SeriesAttr");
    if ((this.conditionList != null) && (conditionCount() > 0))
    {
      paramXMLPrintWriter.startTAG("ConditionList");
      for (int i = 0; i < conditionCount(); ++i)
        ReportXMLUtils.writeXMLable(paramXMLPrintWriter, getCondition(i), "Condition");
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("ConditionList"))
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final SeriesAttr this$0;

          public void readXML()
          {
            if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("Condition")))
            {
              DataSeriesCondition localDataSeriesCondition = (DataSeriesCondition)ReportXMLUtils.readXMLable(paramXMLableReader);
              this.this$0.addCondition(localDataSeriesCondition);
            }
          }
        });
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    int i;
    SeriesAttr localSeriesAttr = (SeriesAttr)super.clone();
    if (this.conditionList != null)
    {
      localSeriesAttr.conditionList = new ArrayList();
      for (i = 0; i < conditionCount(); ++i)
        localSeriesAttr.addCondition((DataSeriesCondition)getCondition(i).clone());
    }
    return localSeriesAttr;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof SeriesAttr))
      return false;
    SeriesAttr localSeriesAttr = (SeriesAttr)paramObject;
    if (localSeriesAttr.conditionCount() != conditionCount())
      return false;
    for (int i = 0; i < localSeriesAttr.conditionCount(); ++i)
      if (!(Equals.equals(localSeriesAttr.getCondition(i), getCondition(i))))
        return false;
    return true;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject1 = new JSONObject();
    localJSONObject1.put("seriesAttrType", getSeriesAttrType());
    if ((this.conditionList != null) && (conditionCount() > 0))
    {
      Object[] arrayOfObject1 = this.conditionList.toArray();
      Object[] arrayOfObject2 = new Object[arrayOfObject1.length];
      for (int i = 0; i < arrayOfObject2.length; ++i)
      {
        JSONObject localJSONObject2 = new JSONObject();
        Object localObject = arrayOfObject1[i];
        if (localObject instanceof DataSeriesCondition)
        {
          DataSeriesCondition localDataSeriesCondition = (DataSeriesCondition)localObject;
          localJSONObject2.put("conditionType", localDataSeriesCondition.getConditionType());
          localJSONObject2.put("condition", localDataSeriesCondition.toJSONObject());
        }
        arrayOfObject2[i] = localJSONObject2;
      }
      localJSONObject1.put("conditionList", arrayOfObject2);
    }
    return localJSONObject1;
  }
}